{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "07b2a8ec",
   "metadata": {},
   "source": [
    "# CartoLayer - styles\n",
    "\n",
    "Render cloud data with color bins, categories and continous style."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "30353b70",
   "metadata": {},
   "outputs": [],
   "source": [
    "import pydeck as pdk\n",
    "import pydeck_carto as pdkc\n",
    "from carto_auth import CartoAuth"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "f4a7e937",
   "metadata": {},
   "outputs": [],
   "source": [
    "carto_auth = CartoAuth.from_oauth()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "f90a430c",
   "metadata": {},
   "outputs": [],
   "source": [
    "pdkc.register_carto_layer()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "89ad2747",
   "metadata": {},
   "outputs": [],
   "source": [
    "layer = pdk.Layer(\n",
    "    \"CartoLayer\",\n",
    "    data=\"SELECT geom, pct_higher_ed FROM `cartobq.public_account.higher_edu_by_county`\",\n",
    "    type_=pdkc.MapType.QUERY,\n",
    "    connection=pdkc.CartoConnection.CARTO_DW,\n",
    "    credentials=pdkc.get_layer_credentials(carto_auth),\n",
    "    get_fill_color=pdkc.styles.color_bins(\n",
    "        \"pct_higher_ed\", [0, 20, 30, 40, 50, 60, 70], \"PinkYl\"\n",
    "    ),\n",
    "    get_line_color=[0, 0, 0, 100],\n",
    "    line_width_min_pixels=0.5,\n",
    "    pickable=True,\n",
    ")\n",
    "\n",
    "view_state = pdk.ViewState(latitude=38, longitude=-98, zoom=3)\n",
    "\n",
    "tooltip = {\"text\": \"Higher education percentage: {pct_higher_ed} %\"}\n",
    "\n",
    "pdk.Deck(\n",
    "    layer, map_style=pdk.map_styles.ROAD, initial_view_state=view_state, tooltip=tooltip\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "e6db5241",
   "metadata": {},
   "outputs": [],
   "source": [
    "layer = pdk.Layer(\n",
    "    \"CartoLayer\",\n",
    "    data=\"SELECT geom, landuse_type FROM `cartobq.public_account.wburg_parcels`\",\n",
    "    type_=pdkc.MapType.QUERY,\n",
    "    connection=pdkc.CartoConnection.CARTO_DW,\n",
    "    credentials=pdkc.get_layer_credentials(carto_auth),\n",
    "    get_fill_color=pdkc.styles.color_categories(\n",
    "        \"landuse_type\",\n",
    "        [\n",
    "            \"Multi-Family Walk-Up Buildings\",\n",
    "            \"Multi-Family Elevator Buildings\",\n",
    "            \"Mixed Residential And Commercial Buildings\",\n",
    "            \"Parking Facilities\",\n",
    "            \"1 and 2 Family Buildings\",\n",
    "            \"Commercial and Office Buildings\",\n",
    "            \"Vacant Land\",\n",
    "            \"Public Facilities and Institutions\",\n",
    "            \"Transportation and Utility\",\n",
    "            \"Open Space and Outdoor Recreation\",\n",
    "            \"Industrial and Manufacturing\",\n",
    "        ],\n",
    "        \"Bold\",\n",
    "    ),\n",
    "    get_line_color=[0, 0, 0, 100],\n",
    "    line_width_min_pixels=0.5,\n",
    "    pickable=True,\n",
    ")\n",
    "\n",
    "view_state = pdk.ViewState(latitude=40.715, longitude=-73.959, zoom=14)\n",
    "\n",
    "tooltip = {\n",
    "    \"html\": \"<b>Land use type:</b><br>{landuse_type}\",\n",
    "    \"style\": {\n",
    "        \"color\": \"black\",\n",
    "        \"backgroundColor\": \"#84D2F6\",\n",
    "    },\n",
    "}\n",
    "\n",
    "pdk.Deck(\n",
    "    layer,\n",
    "    map_style=pdk.map_styles.LIGHT,\n",
    "    initial_view_state=view_state,\n",
    "    tooltip=tooltip,\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "3c06e8b6",
   "metadata": {},
   "outputs": [],
   "source": [
    "layer = pdk.Layer(\n",
    "    \"CartoLayer\",\n",
    "    data=\"SELECT geom, value FROM cartobq.public_account.temps\",\n",
    "    type_=pdkc.MapType.QUERY,\n",
    "    connection=pdkc.CartoConnection.CARTO_DW,\n",
    "    credentials=pdkc.get_layer_credentials(carto_auth),\n",
    "    get_fill_color=pdkc.styles.color_continuous(\n",
    "        \"value\", [70, 75, 80, 85, 90, 95, 100], \"Peach\"\n",
    "    ),\n",
    "    point_radius_min_pixels=2.5,\n",
    "    pickable=True,\n",
    ")\n",
    "\n",
    "view_state = pdk.ViewState(latitude=34, longitude=-98, zoom=3)\n",
    "\n",
    "tooltip = {\n",
    "    \"html\": \"<b>Temperature:</b> {value}°F\",\n",
    "    \"style\": {\n",
    "        \"color\": \"white\",\n",
    "    },\n",
    "}\n",
    "\n",
    "pdk.Deck(\n",
    "    layer, map_style=pdk.map_styles.ROAD, initial_view_state=view_state, tooltip=tooltip\n",
    ")"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.10"
  },
  "vscode": {
   "interpreter": {
    "hash": "397f9d86bc6cffaf98711878e048d4ea1b6f37d57e9a5761ac2bec56bfc5b368"
   }
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
